package com.nirvana.flatbuffers;


/**
 * Copyright (c) 2022 Aoshu.Co.Ltd. All rights reserved.
 *
 * @author :    zhouqichun
 * @create :    2025/11/14 10:13
 * @description :
 **/
public class DropResolver implements IResolve {
    @Override
    public boolean canResolve(String propertyType) {
        return "Drop".equals(propertyType);
    }

    @Override
    public String resolve(StringBuilder objectPreContent, String defName, String propertyName, String propertyType) {
        objectPreContent.append("""
                                    val %sOffset = DropFb.createDropFb(builder, m.%s.dropId, m.%s.times, m.%s.weight, m.%s.bind)
                    """.formatted(
                propertyName,
                propertyName,
                propertyName,
                propertyName,
                propertyName
        ));
        return "%sOffset".formatted(propertyName);
    }

    @Override
    public String resolveVector(StringBuilder objectPreContent, String defName, String propertyName, String propertyType) {
        objectPreContent.append("""
                                val %sOffsets = m.%s.map(p => {
                                    DropFb.createDropFb(p.dropId, p.times, p.weight, p.bind)
                                })
                """.formatted(
                propertyName,
                propertyName
        ));
        return "%sOffsets".formatted(propertyName);
    }
}
